/**
 * Created by Administrator on 2017/3/21.
 */
import React, {Component} from 'react';
import { Form, Input, Radio, Select, Switch, Button, Tooltip, Icon } from 'antd';
import request from '@/utils/request';
import { connect } from 'dva';
import styles from '../../layouts/password.less';
const FormItem = Form.Item;
const { TextArea } = Input;

const RadioGroup = Radio.Group;
const Option = Select.Option;
class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      all_roles:[],
      companies:[],
      level:0,
      management_companies:sessionStorage.getItem('management_companies')?JSON.parse(sessionStorage.getItem('management_companies')):[],
    };
  }
  componentDidMount() {
    const that=this;
    // request(`/companies`, {
    //   method: 'GET',
    // }).then((response)=> {
    //   console.log('all companies', response)
    //   if(response.status===200){
    //     that.setState({
    //       companies:response.data.data
    //     })
    //   }
    // })
  }
  changePassword=(e)=> {
    let value=e.target.value
    let level = 0;
    //正则表达式验证符合要求的
    if(/\d/.test(value)) level++; //数字
    if(/[A-Z]/.test(value)) level++; //小写
    if(/[a-z]/.test(value)) level++; //特殊字符
    if(value.length < 8||value.length > 16)  level=0;
    //逻辑处理
    this.setState({
      level:level
    })
  }
  render() {
    const formItemLayoutWithLabel = {
      labelCol: {
        xs: {span: 24},
        sm: {span: 7},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 15},
      }
    };

    const {getFieldDecorator} = this.props.form;
    let company_sign=''
    console.log('this.props.editRecord.management_companies.length',this.props.editRecord.management_companies.length)
    if(this.props.editRecord.management_companies.length===10){
      company_sign=''
    }else if(this.props.editRecord.management_companies.length===6){
      company_sign='e'
    }else if(this.props.editRecord.management_companies.length===4){
      company_sign='w'
    }
    console.log('company_ids',company_sign)
    return (
      <div>
        <Form onSubmit={this.handleSubmit}>
          <FormItem
            {...formItemLayoutWithLabel}
            label={(
              <span>
                账号名称
            </span>
            )}
          >
            {getFieldDecorator('username', {
              initialValue: this.props.editRecord ? this.props.editRecord.username : '',
              rules: [{ required: true, message: '请输入名称' }],
            })(
              <Input disabled={true}/>
            )}
          </FormItem>
          <Form.Item label="可管理分站"
                     {...formItemLayoutWithLabel}
          >
            {getFieldDecorator('company_sign', {
              initialValue:company_sign,
            })(
              <Select  placeholder="请选择">
                <Option value={''}>全部</Option>
                <Option value={'e'}>东区事业部</Option>
                <Option value={'w'}>西区事业部</Option>
              </Select>,
            )}
          </Form.Item>
          {/*<Form.Item label="可管理公司"
                     {...formItemLayoutWithLabel}
          >
            {getFieldDecorator('management_companies', {
              initialValue:this.props.editRecord.management_companies.map((item,index)=>{
                return item.id
              }),
            })(
              <Select mode="multiple" placeholder="请选择">
                {
                  this.state.companies.map((item,index)=>{
                    return <Option key={index} value={item.id}>
                      {item.name}
                    </Option>
                  })
                }
              </Select>,
            )}
          </Form.Item>
*/}

        </Form>
      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);


